package com.library.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 登出处理Servlet
 */
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        // 获取session
        HttpSession session = request.getSession(false);
        
        // 如果session存在，移除用户信息并销毁session
        if (session != null) {
            session.removeAttribute("user");
            session.invalidate();
        }
        
        // 重定向到登录页面
        response.sendRedirect("login.jsp");
    }
}
